import processing.core.PConstants;


public class Bar {
	float x, y;
	float width, height;
	private int color;
	int index;
	String name;
	int count;
	int listeners;
	
	public Bar(float _x, float _y, float w, float h) {
		x = _x;
		y = _y - h;
		width = w;
		height = h;
		color = 0;
	}

	public Bar(float _x, float _y, float w, float h, int c) {
		x = _x;
		y = _y - h;
		width = w;
		height = h;
		color = c;
	}
	
	public Bar(float _x, float _y, float w, float h, int c, int i) {
		x = _x;
		y = _y - h;
		width = w;
		height = h;
		color = c;
		index = i;
	}
	
	public Bar(float _x, float _y, float w, float h, int c, int i, String nm, int cnt, int l) {
		x = _x;
		y = _y - h;
		width = w;
		height = h;
		color = c;
		index = i;
		name = nm;
		count = cnt;
		listeners = l;
	}
	
	public boolean mouseOver() {
        if(GLOBAL.processing.mouseX > x && GLOBAL.processing.mouseX < x+width && 
                        GLOBAL.processing.mouseY > y && GLOBAL.processing.mouseY < y+height) return true;
        return false;
    }

	public void draw() {	
		GLOBAL.processing.stroke(0);
		
		if(mouseOver()) {
			GLOBAL.processing.textAlign(PConstants.CENTER);
			GLOBAL.processing.fill(0);
			GLOBAL.processing.textFont(GLOBAL.fontSegoe, 12);
			GLOBAL.processing.text(name + "\nPlays: " + count + "\nListeners: " + listeners, x, y+height+20);
			GLOBAL.processing.textAlign(PConstants.LEFT);
			GLOBAL.processing.fill(GLOBAL.colorBarHighlight);
			
			if(GLOBAL.processing.mousePressed) {
				GLOBAL.sendEventToView((int) y, index);
			}
		}
		else
			GLOBAL.processing.fill(color);
		
		GLOBAL.processing.rect(x, y, width, height);

	}
}
